<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import="java.util.List" %>
<%@ page import="javax.jdo.PersistenceManager" %>
<%@ page import="com.google.appengine.api.users.User" %>
<%@ page import="com.google.appengine.api.users.UserService" %>
<%@ page import="com.google.appengine.api.users.UserServiceFactory" %>
<%@ page import="CRM.Greeting" %>
<%@ page import="CRM.PMF" %>
<%@ page import="CRM.Company" %>
<%@ page import="CRM.Contact" %>
<%@ page import="CRM.Note" %>
<%@ page import="CRM.Project" %>
<%@ page import="CRM.Task" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">

<html>
    <head>
    <link type="text/css" rel="stylesheet" href="/stylesheets/main.css" />
    </head>
    <body>
        <%
        UserService userService = UserServiceFactory.getUserService();
        User user = userService.getCurrentUser();

        if(user == null)
            {
        %>
        <p>Please
            <a href="<%= userService.createLoginURL(request.getRequestURI()) %>">sign in</a>
        </p>
        <%
            }
        else
            {
            %>
            <p> Welcome
                <%=user.getNickname()%>
        <a href="<%= userService.createLogoutURL(request.getRequestURI()) %>">Sign out</a>
            </p>
        <%
    PersistenceManager pm = PMF.get().getPersistenceManager();
    String query = "select from " + Task.class.getName() + " order by deadLine asc";
    List<Task> tasks = (List<Task>) pm.newQuery(query).execute();
    if (tasks.isEmpty()) {
%>
<p>You have no remaining tasks.</p>
<%
    } else {
        for (Task t : tasks) {
            
%>
<p><%t.getCreatedOn();%></p>
<p><%t.getText();%></p>
<p>Related with : <%t.getContact();%><%t.getCompany();%><%t.getProject();%></p>
<p><%t.getDeadLine();%></p>

<%}%>
<%}%>

<%pm.close();%>
<%}%>

    </body>
</html>
